package com.lb.multithread;

import java.util.concurrent.TimeUnit;

/**
 * @version 1.0
 * @Author: Edward
 * @Date: 2021/4/15 10:13
 * @Description:
 */
public class ThreadLocal1 {
    static ThreadLocal<Person> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(tl.get());
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tl.set(new Person());
        }).start();
    }


    static class Person {
        private String name = "蓝莲花";
    }
}
